<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.7
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############

$THEME->addBreadcrumb($this->adminUrl.'/dev-stats/', $this->lang('ap_title_dev-stats'));

$dir = '/var/www/jx.loc';




$numFiles = countFiles($dir, 'php');


echo $numFiles.' files in the website <br />';



$numLines = countLines($dir, 'php');


echo $numLines.' lines in the website<br />';






function countLines($dir, $ext=''){
    $num = 0;
    $dh = opendir($dir);
    while($file = readdir($dh)){
        if($file == '.' || $file == '..') continue;
        if($ext != '' && !is_dir($dir.'/'.$file)){
            $pathInfo = pathinfo($dir.'/'.$file);
            if($pathInfo['extension']==$ext){
                // bingo!
                $fc = file_get_contents($dir.'/'.$file);
                $lines = explode("\n", $fc);
                $num += count($lines);
            }
        }else if($ext == '' && is_file($dir.'/'.$file)){
            $fc = file_get_contents($dir.'/'.$file);
            $lines = explode("\n", $fc);
            $num += count($lines);
        };
        
        if(is_dir($dir.'/'.$file)){
            $num += countLines($dir.'/'.$file, $ext);
        }
    };
    return $num;
}











function countFiles($dir, $ext=''){
    $num = 0;
    $dh = opendir($dir);

    while($file = readdir($dh)){
        if($file == '.' || $file == '..') continue;
         if($ext != '' && !is_dir($dir.'/'.$file)){
            $pathInfo = pathinfo($dir.'/'.$file);
            if($pathInfo['extension']==$ext){
                // bingo!
                $num ++;
            }
        }else if($ext == '' && file_exists($dir.'/'.$file) && !is_dir($dir.'/'.$file)){
            $num++;
        };

        if(is_dir($dir.'/'.$file)){
            $num += countFiles($dir.'/'.$file, $ext);
        }
    };
    return $num;
}




